<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<title>修改</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport"
		content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="/src/css/main.css" media="all">
	<style>
		.formUl li {
			width: 96% !important;
		}
	</style>
</head>

<body>
	<div id="layui-body-content" class="layui-fluid">
		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="" lay-filter="layui-form-Table">
					<ul class="layui-form layui-form-pane formUl" style="margin: 15px;">
						<li class="layui-form-item">
							<label class="layui-form-label">用户名</label>
							<div class="layui-input-block">
								<input type="text" id="username" name="username" lay-verify="required"
									autocomplete="off" placeholder="请输入用户名" class="layui-input">
							</div>
						</li>
						<li class="layui-form-item">
							<label class="layui-form-label">真实姓名</label>
							<div class="layui-input-block">
								<input type="text" name="truename" lay-verify="required" autocomplete="off"
									placeholder="请输入真实姓名" class="layui-input">
							</div>
						</li>
						<li class="layui-form-item">
							<label class="layui-form-label">单位部门名称</label>
							<div class="layui-input-block">
								<input type="text" id="deptname" name="deptname" lay-verify="required"
									autocomplete="off" placeholder="请选择单位或部门" class="layui-input"
									style="cursor: pointer;" onkeydown="return false;" oncontextmenu="return false;">
								<input type="text" class="layui-hide" id="deptid" name="deptid">

							</div>
						</li>
						<li class="layui-form-item">
							<label class="layui-form-label">电话号码</label>
							<div class="layui-input-block">
								<input type="text" name="phonenumber" lay-verify="required" autocomplete="off"
									placeholder="请输入电话号码" class="layui-input">
							</div>
						</li>
						<li class="layui-form-item">
							<label class="layui-form-label">电子邮箱</label>
							<div class="layui-input-block">
								<input type="text" name="email" lay-verify="email" autocomplete="off"
									placeholder="请输入电子邮箱" class="layui-input">
							</div>
						</li>
						<li class="layui-form-item">
							<label class="layui-form-label">办公电话</label>
							<div class="layui-input-block">
								<input type="text" name="bgdh" lay-verify="phone|gdphone" autocomplete="off"
									placeholder="请输入办公电话" class="layui-input">
							</div>
						</li>
					</ul>

					<div style="text-align: center;">
						<input type="hidden" name="id" value="0">
						<button class="layui-btn" lay-submit lay-filter="YjbtnSave" id="YjbtnSave"
							type="button">提交</button>
					</div>
				</form>
			</div>
		</div>
	</div>
	<script src="/layui/layui.js"></script>
	<script>
		layui.config({
			base: '/src/'
		}).use(['index'], function () {
			var admin = layui.admin
				, main = layui.main
				, form = layui.form
				, setter = layui.setter
				, treeSelect = layui.treeSelect
				, table = parent.layui.table;
			var $ = layui.$;
			// 自定义固话电话验证规则
			form.verify({
				gdphone: function (value, item) {
					var reg = /^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/;
					if (!reg.test(value)) {
						return '请输入正确的固话电话格式';
					}
				}
			});

			$("#username").attr("readonly", true);
			$("#username").attr("disabled", true);
			//加载表单内容
			admin.req({
				url: 'system/users/GetUserInfo'
				, type: 'get'
				, done: function (res) {
					if (res.successful) {
						form.val("layui-form-Table", {
							"id": res.data.id
							, "username": res.data.username
							, "truename": res.data.truename
							, "deptid": res.data.deptid
							, "deptname": res.data.deptname
							, "phonenumber": res.data.phonenumber
							, "email": res.data.email
							, "bgdh": res.data.bgdh
							, "dwdz": res.data.dwdz
						});
					}
				}
			});

			//显示单位或部门
			$("#deptname").click(function () {
				layer.open({
					type: 2,
					title: '选择所属单位或部门',
					shadeClose: true,
					area: ['50%', '90%'],
					content: setter.views + 'jg/user/seldept.html?deptid=' + deptid
				});
			});
			//保存
			form.render().on('submit(YjbtnSave)', function (data) {
				admin.req({
					url: 'system/users/UpdateZFRY'
					, data: JSON.stringify(data.field)
					, contentType: 'application/json'
					, type: 'put'
					, done: function (res) {
						if (res.successful) {
							main.msg_success(res.msg);
							table.reload('LAY-app-users-list');
						}
						else {
							main.msg_error(res.msg);
						}
					}
				});
			});

		});
	</script>
</body>

</html>